package com.xhu.servlet;


import com.xhu.bean.pojo.saleperform;
import com.xhu.service.SgService;
import com.xhu.service.impl.SgServiceImpl;
import com.xhu.utils.BaseServlet;
import com.xhu.utils.FormatUtils;
import com.xhu.utils.ResultData;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

@WebServlet("/SgServlet/*")
public class SgServlet extends BaseServlet {
    /*public ResultData findAll(HttpServletRequest request){
        SfService spService=new SfServiceImpl();
        List<SalesForecast> list=spService.findAll();
        return ResultData.ok().data(list);
    }*/

    public ResultData add(HttpServletRequest request){


        String saleperform_code=request.getParameter("saleperform_code");
        String emp_name=request.getParameter("emp_name");
        String dept_name=request.getParameter("dept_name");
        String perform_level=request.getParameter("perform_level");
        String des=request.getParameter("des");


        saleperform saleperform =new saleperform();
        saleperform.setCreate_time(new Date());
        saleperform.setDept_name(dept_name);
        saleperform.setDes(des);
        saleperform.setPerform_level(perform_level);
        saleperform.setSaleperform_code(saleperform_code);
        saleperform.setEmp_name(emp_name);
        saleperform.setCurrent_name("admin");
        saleperform.setEmp_count("10");

        SgService sgService=new SgServiceImpl();
        boolean tf=sgService.add(saleperform);
        return ResultData.ok().msg(tf?"添加成功":"添加失败");
    }

    public ResultData list(HttpServletRequest request){
        Integer page= FormatUtils.stringFormatInteger(request.getParameter("page"));
        Integer limit=FormatUtils.stringFormatInteger(request.getParameter("limit"));

        System.out.println("成功运行到这");
        SgService sgService=new SgServiceImpl();
        List<saleperform> list=sgService.queryPage(page,limit);

        return ResultData.ok().data(list);
    }

    public ResultData list_search(HttpServletRequest request){
        Integer page= FormatUtils.stringFormatInteger(request.getParameter("page"));
        Integer limit=FormatUtils.stringFormatInteger(request.getParameter("limit"));
        String search_name=request.getParameter("search_name");

        System.out.println("成功运行到这");
        SgService sgService=new SgServiceImpl();
        if(search_name==""){
            List<saleperform> list=sgService.queryPage(page,limit);

            return ResultData.ok().data(list);
        }else{
            List<saleperform> list=sgService.queryPage(page,limit,search_name);

            return ResultData.ok().data(list);
        }

    }

    public ResultData upData(HttpServletRequest request){

        String saleperform_id=request.getParameter("saleperform_id");

        String saleperform_code=request.getParameter("saleperform_code");
        String emp_name=request.getParameter("emp_name");
        String dept_name=request.getParameter("dept_name");
        String perform_level=request.getParameter("perform_level");
        String des=request.getParameter("des");

        System.out.println("sg updata  "+saleperform_code);

        saleperform saleperform =new saleperform();
        saleperform.setDept_name(dept_name);
        saleperform.setDes(des);
        saleperform.setPerform_level(perform_level);
        saleperform.setSaleperform_code(saleperform_code);
        saleperform.setEmp_name(emp_name);

        SgService sgService=new SgServiceImpl();
        boolean tf=sgService.upData(saleperform,saleperform_id);

        System.out.println("sg tf "+tf);
        return ResultData.ok().msg(tf?"更新成功":"更新失败");

    }

    public ResultData del(HttpServletRequest request){
        String saleperform_id=request.getParameter("saleperform_id");

        System.out.println("del中的:"+saleperform_id);
        SgService sgService=new SgServiceImpl();
        boolean tf=sgService.del(saleperform_id);
        return ResultData.ok().msg(tf?"删除成功":"删除失败");

    }

}
